<template>
  <a-config-provider :locale="myLocale">
    <div id="app">
      <router-view />
    </div>
  </a-config-provider>
</template>

<script>
import { domTitle, setDocumentTitle } from "@/utils/domUtil";
import { i18nRender } from "@/locales";
import zhCN from "ant-design-vue/lib/locale-provider/zh_CN";
import enGB from "ant-design-vue/lib/locale-provider/en_GB";

export default {
  data() {
    return {
      myLocale: enGB,
    };
  },
  methods: {

    
  },
  mounted() {
    let that = this;
    window.addEventListener("setItemEvent", function (e) {
      if (e.key == "lang") {
        let lang = JSON.parse(e.value);
        console.log(lang,12);
        if (lang == "zh-EN") {
          that.myLocale = enGB;
        } else {
          that.myLocale = zhCN;
        }
      }
    });
  },
  computed: {
    locale() {
      // 只是为了切换语言时，更新标题
      const { title } = this.$route.meta;
      title && setDocumentTitle(`${i18nRender(title)} - ${domTitle}`);

      return this.$i18n.getLocaleMessage(this.$store.getters.lang).antLocale;
    },
  },
};
// const debounce = (fn, delay) => {
//   let timer = null;
//   return function () {
//     let context = this;
//     let args = arguments;
//     clearTimeout(timer);
//     timer = setTimeout(function () {
//       fn.apply(context, args);
//     }, delay);
//   };
// };

// const _ResizeObserver = window.ResizeObserver;
// window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
//   constructor(callback) {
//     callback = debounce(callback, 16);
//     super(callback);
//   }
// };
</script>